<%@ page pageEncoding="UTF-8" %>
<!doctype html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/css/bootstrap.min.css"
          integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/5.11.2/css/all.css" rel="stylesheet">
    <link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.15.3/dist/bootstrap-table.min.css">
    <link href="https://cdn.bootcdn.net/ajax/libs/toastr.js/2.1.4/toastr.min.css" rel="stylesheet">
    <link href="https://cdn.bootcdn.net/ajax/libs/bootstrap-fileinput/5.1.2/css/fileinput.min.css" rel="stylesheet">
    <title>随便打TCS系统</title>
</head>

<body class="nav-md">
<%--<div>--%>
    <div class="container-fluid" style="padding-left: 235px">
        <div>
            <div id="toolbar" class="btn-group">
                <div class="row">
<%--                    <div class="col-14" style="margin-left: 15px">--%>
<%--                        <form class="form-inline" id="formSelect">--%>
<%--                            <div class="form-group mb-2">--%>
<%--                                <button type="button" id="search" class="btn btn-success">查询</button>--%>
<%--                                <button type="reset" id="reset" class="btn btn-danger">重置</button>--%>
<%--                            </div>--%>
<%--                        </form>--%>
<%--                    </div>--%>
                    <div class="col-14" style="margin-left: 20px">
                        <button type="button" class="btn btn-primary" data-toggle="modal" id="addModal">
                            新增
                        </button>
                    </div>
                </div>
            </div>
            <table id="table"></table>
        </div>
        <!-- 详情数据表格 -->
        <div class="modal fade" id="detailShow" tabindex="-1" role="dialog" aria-labelledby="detailShowTitle">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title" id="detailShowTitle">详情- <span id="detailShowSpan"></span></h4>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                    </div>
                    <div class="modal-body">
                        <div class="container-fluid">
                            <div id="toolbarShow" class="btn-group">
                                <div class="row">
                                    <div class="col-14" style="margin-left: 15px">
                                        <form class="form-inline" id="formShowSelect">
                                            <div class="col-14" style="margin-left: 20px">
                                                <button type="button" class="btn btn-primary" data-toggle="modal" id="addDetailModal">
                                                    新增
                                                </button>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                            </div>
                            <table id="tableDetailShow"></table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- 新增 -->
        <div class="modal fade" id="addShow" tabindex="-1" role="dialog" aria-labelledby="addShowTitle">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title" id="addShowTitle">新增话费礼包</h4>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                    </div>
                    <div class="modal-body">
                        <form id="formAdd">
                            <div class="form-row">
                                <div class="form-group " style="width: 100%">
                                    <input type="text" class="form-control" id="planNameAdd" placeholder="请输入话费礼包名称">
                                </div>
                            </div>
                            <div class="form-row">
                                <div class="form-group " style="width: 100%">
                                    <input type="text" class="form-control" id="planPriceAdd" placeholder="请输入话费礼包单价">
                                </div>
                            </div>
                            <div class="form-row">
                                <input type="text" hidden class="form-control" id="planPicSrcAdd"/>
                                <label for="planPicAdd">话费礼包图：</label>
                                <div class="form-group" style="width: 100%;">
                                    <input id="planPicAdd" type="file" name="file">
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button id="addPost" type="button" class="btn btn-primary">新增</button>
                    </div>
                </div>
            </div>
        </div>

        <!-- 修改 -->
        <div class="modal fade" id="updateShow" tabindex="-1" role="dialog" aria-labelledby="updateShowTitle">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title" id="updateShowTitle">修改话费礼包</h4>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                    </div>
                    <div class="modal-body">
                        <form id="formUpdate">
                            <input type="text" hidden class="form-control" id="idUpdate"/>
                            <div class="form-row">
                                <div class="form-group" style="width: 100%">
                                    <label for="planNameUpdate">话费礼包名称：</label>
                                    <input type="text" class="form-control" id="planNameUpdate" placeholder="请输入话费礼包名称">
                                </div>
                            </div>
                            <div class="form-row">
                                <div class="form-group" style="width: 100%">
                                    <label for="planPriceUpdate" style="display: block;">话费礼包单价：</label>
                                    <input type="text" class="form-control" id="planPriceUpdate" placeholder="请输入话费礼包单价">
                                </div>
                            </div>
                            <div class="form-row">
                                <input type="text" hidden class="form-control" id="planPicSrcUpdate"/>
                                <label for="planPicUpdate">话费礼包图：</label>
                                <div class="form-group" style="width: 100%;">
                                    <input id="planPicUpdate" type="file" name="file">
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary" id="updatePost">修改</button>
                    </div>
                </div>
            </div>
        </div>

        <!-- 新增 -->
        <div class="modal fade" id="addDetailShow" tabindex="-1" role="dialog" aria-labelledby="addDetailShowTitle">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title" id="addDetailShowTitle">新增礼包详情</h4>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                    </div>
                    <div class="modal-body">
                        <form id="formDetailAdd">
                            <div class="form-row">
                                <div class="form-group " style="width: 100%">
                                    <input type="text" class="form-control" id="planNameDetailAdd" placeholder="请输入礼包详情名称">
                                </div>
                            </div>
                            <div class="form-row">
                                <div class="form-group " style="width: 100%">
                                    <input type="text" class="form-control" id="planPriceDetailAdd" placeholder="请输入礼包详情价值">
                                </div>
                            </div>
                            <div class="form-row">
                                <input type="text" hidden class="form-control" id="planPicSrcDetailAdd"/>
                                <label for="planPicAdd">礼包详情图：</label>
                                <div class="form-group" style="width: 100%;">
                                    <input id="planPicDetailAdd" type="file" name="file">
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button id="addDetailPost" type="button" class="btn btn-primary">新增</button>
                    </div>
                </div>
            </div>
        </div>

        <!-- 修改 -->
        <div class="modal fade" id="updateDetailShow" tabindex="-1" role="dialog" aria-labelledby="updateDetailShowTitle">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title" id="updateDetailShowTitle">修改礼包详情</h4>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                    </div>
                    <div class="modal-body">
                        <form id="formDetailUpdate">
                            <input type="text" hidden class="form-control" id="idDetailUpdate"/>
                            <div class="form-row">
                                <div class="form-group" style="width: 100%">
                                    <label for="planNameUpdate">礼包详情名称：</label>
                                    <input type="text" class="form-control" id="planNameDetailUpdate" placeholder="请输入话费礼包名称">
                                </div>
                            </div>
                            <div class="form-row">
                                <div class="form-group" style="width: 100%">
                                    <label for="planPriceUpdate" style="display: block;">礼包详情价值：</label>
                                    <input type="text" class="form-control" id="planPriceDetailUpdate" placeholder="请输入话费礼包单价">
                                </div>
                            </div>
                            <div class="form-row">
                                <input type="text" hidden class="form-control" id="planPicSrcDetailUpdate"/>
                                <label for="planPicUpdate">礼包详情图：</label>
                                <div class="form-group" style="width: 100%;">
                                    <input id="planPicDetailUpdate" type="file" name="file">
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary" id="updateDetailPost">修改</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
<%--</div>--%>

</body>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
        integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
        crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/js/bootstrap.min.js"
        integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI"
        crossorigin="anonymous"></script>
<script src="https://unpkg.com/bootstrap-table@1.15.3/dist/bootstrap-table.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/bootstrap-table/1.15.3/locale/bootstrap-table-zh-CN.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/toastr.js/2.1.4/toastr.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/bootstrap-fileinput/5.1.2/js/plugins/purify.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/bootstrap-fileinput/5.1.2/js/fileinput.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/bootstrap-fileinput/5.1.2/js/locales/zh.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/bootstrap-fileinput/5.1.2/js/locales/fa.min.js"></script>
<script>
    $(function () {
        $(document).ajaxComplete(function (event, xhr, settings) {
            let url = xhr.getResponseHeader("redirectUrl");

            let enable = xhr.getResponseHeader("enableRedirect");

            if((enable === "true") && (url !== "")){
                let win = window;
                while(win !== win.top){
                    win = win.top;
                }
                win.location.href = url;
            }
        })
        Date.prototype.Format = function (fmt) {
            const o = {
                "M+": this.getMonth() + 1,
                "d+": this.getDate(),
                "h+": this.getHours(),
                "m+": this.getMinutes(),
                "s+": this.getSeconds(),
                "q+": Math.floor((this.getMonth() + 3) / 3),
                "S": this.getMilliseconds()
            };
            if (/(y+)/.test(fmt))
                fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            for (let k in o)
                if (new RegExp("(" + k + ")").test(fmt))
                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            return fmt;
        };
        var sid = "";
        var operateEvents = {
            "click #showDetailId": function (e, value, row, index) {
                let detailShow = $('#detailShow');
                let pHeight = $(window).height();
                detailShow.css({ "height": pHeight, "position": "absolute", "margin-left": "16%", "width": "100%", "padding-right": "16%" });
                $("#detailShow .modal-dialog").css({ "height": pHeight - 30, "max-width": "fit-content" });
                $("#detailShow .modal-dialog .modal-content").css({ "height": pHeight - 30});
                detailShow.modal('handleUpdate');
                detailShow.modal('show');
                sid = row.id;
                $('#detailShowSpan').text(row.planName);
                bootstrapTableShow.queryParams = function (params) {
                    return {
                        offset: (params.offset / params.limit) + 1,
                        limit: params.limit,
                        callPlan: sid
                    };
                };
                const tableDetailShow = $('#tableDetailShow');
                tableDetailShow.bootstrapTable('destroy');
                tableDetailShow.bootstrapTable(bootstrapTableShow);
            },
            "click #showUpdateId": function (e, value, row, index) {
                $('#formUpdate')[0].reset() ;
                $('#updateShow').modal('show');
                $('#idUpdate').val(row.id);
                $('#planNameUpdate').val(row.planName);
                $('#planPriceUpdate').val(row.planPrice);
                $('#planPicSrcUpdate').val(row.planPic);
                updateImg([ row.planPic ], fileInputOption, "planPicUpdate", "planPicSrcUpdate");
            },
            "click #showDeleteId": function (e, value, row, index) {
                $.ajax({
                    url: "/SbdVoip/admin/commodityCallPlan/commodityCallPlanWebDelete",
                    type: "POST",
                    data: {id: row.id},
                    dataType: "json",
                    contentType: "application/x-www-form-urlencoded",
                    success: function (result) {
                        if (result.code !== 2000) {
                            toastr.error(result.message);
                            return
                        }
                        const table = $('#table');
                        table.bootstrapTable('destroy');
                        table.bootstrapTable(bootstrapTable);
                        toastr.success(result.message);
                    }
                });
            }
        };

        // 文件上传参数
        const fileInputOption = {
            language: 'zh',
            browseOnZoneClick: true,
            allowedFileExtensions: ['jpg', 'gif', 'png', 'jpeg'],
            uploadUrl: '/SbdVoip/layfile/uploadFile1',
            // 是否显示上传按钮
            showUpload: true,
            // 显示移除按钮
            showRemove: false,
            // 是否显示预览
            showPreview: true,
            // 是否显示拖拽区域
            dropZoneEnabled: true,
            // 是否显示文件标题
            showCaption: false,
            minFileCount: 1,
            maxFileCount: 1,
            removeFromPreviewOnError: true,
            layoutTemplates: {
                actionZoom: '<button type="button" class="kv-file-zoom {zoomClass} bi bi-zoom-in" title="{zoomTitle}"><i class="fa fa-search-plus"></i></button>',
                actionDelete: '',
                actionUpload: '',
                actionDrag: '',
                modalMain: '<div id="kvFileinputModal" role="dialog" class="file-zoom-dialog modal fade" tabindex="-1" aria-labelledby="kvFileInputModalLabel"></div>',
                modal: '<div class="modal-dialog modal-lg" role="document">' +
                    '  <div class="modal-content">' +
                    '    <div class="modal-header">' +
                    '      <h3 class="modal-title" id="kvFileInputModalLabel">{heading} <small><span class="kv-zoom-title"></span></small></h3>' +
                    '      <div class="kv-zoom-actions">' +
                    '           <button type="button" class="btn btn-sm btn-kv btn-default btn-outline-secondary btn-toggleheader" title="缩放" data-toggle="button" aria-pressed="false" autocomplete="off">' +
                    '               <i class="fas fa-compress-arrows-alt"></i>' +
                    '           </button>' +
                    '           <button type="button" class="btn btn-sm btn-kv btn-default btn-outline-secondary btn-fullscreen" title="全屏" data-toggle="button" aria-pressed="false" autocomplete="off">' +
                    '               <i class="fas fa-expand"></i>' +
                    '           </button>' +
                    '           <button type="button" class="btn btn-sm btn-kv btn-default btn-outline-secondary btn-borderless" title="无边界模式" data-toggle="button" aria-pressed="true" autocomplete="off">' +
                    '               <i class="fas fa-compress"></i>' +
                    '           </button>' +
                    '           <button type="button" id="close-kv-zoom-actions" class="btn btn-sm btn-kv btn-default btn-outline-secondary" data-dismiss="modal" title="关闭当前预览">' +
                    '               <i class="fas fa-times"></i>' +
                    '           </button>' +
                    '      </div>' +
                    '    </div>' +
                    '    <div class="modal-body">' +
                    '      <div class="floating-buttons"></div>' +
                    '      <div class="kv-zoom-body file-zoom-content"></div>' + '{prev} {next}' +
                    '    </div>' +
                    '  </div>' +
                    '</div>'
            }
        };

        addImg([], fileInputOption, "planPicAdd", "planPicSrcAdd");

        function addImg(srcArray, fileInputOption, objStr, objSrcStr){
            $("#" + objStr).fileinput(fileInputOption).on('fileuploaded', function (event, data, previewId, index) {
                if (data.response.code !== 0) {
                    toastr.error(data.response.msg);
                    return
                }
                $('#' + objSrcStr).val(data.response.data.src);
                $("[id='" + previewId + "'] .kv-file-content img").attr('src', data.response.data.src);
                toastr.success(data.response.msg);
            });
        }

        function updateImg(srcArray, fileInputOption, objStr, objSrcStr){
            let obj = $("#" + objStr);
            obj.fileinput('destroy');
            let fileInputOption1 = fileInputOption;
            fileInputOption1.initialPreviewAsData = true;
            fileInputOption1.initialPreviewFileType = 'image';
            fileInputOption1.initialPreview = srcArray;
            obj.fileinput(fileInputOption1).on('fileuploaded', function (event, data, previewId, index) {
                if (data.response.code !== 0) {
                    toastr.error(data.response.msg);
                    return
                }
                $('#' + objSrcStr).val(data.response.data.src);
                $("[id='" + previewId + "'] .kv-file-content img").attr('src', data.response.data.src);
                toastr.success(data.response.msg);
            });
        }

        $("#kvFileinputModal").on("hidden.bs.modal", function () {
            $("body").attr("class", "modal-open");
        });

        $("#addModal").click(function () {
            $('#formAdd')[0].reset() ;
            $('#addShow').modal('show');
        });

        function actionFormatter(value, row, index) {
            return [
                '<button id="showUpdateId" type="button" class="btn btn-warning">修改</button>',
                '<button id="showDeleteId" type="button" class="btn btn-danger">删除</button>',
                '<button id="showDetailId" type="button" class="btn btn-info">详情</button>'
            ].join('');
        }

        function formatDate(value, row, index) {
            return new Date(parseInt(value)).Format("yyyy-MM-dd hh:mm:ss");
        }

        function planPicFormatter(value, row, index){
            return '<a target="_blank" href="'+ row.planPic +'" class="text-decoration-none">' +
                '<span title="'+ row.planPic +'" class="d-inline-block text-truncate" style="max-width: 150px;">'
                + row.planPic + '</span></a>'
        }

        let columns = [
            {checkbox: true, 'data-halign': 'center', width: 50},
            {field: 'planName', title: '话费礼包名称', align: 'center', width: 300},
            {field: 'planPrice', title: '话费礼包单价', align: 'center', width: 100},
            {field: 'planPic', title: '话费礼包图', align: 'center', width: 300, formatter: planPicFormatter},
            {field: 'createTime', title: '创建时间', align: 'center', width: 272, formatter: formatDate},
            {title: '操作', align: 'center', formatter: actionFormatter, events: operateEvents, width: 500}
        ];

        let bootstrapTable = {
            url: '/SbdVoip/admin/commodityCallPlan/commodityCallPlanWebList',
            pagination: true,
            toolbar: '#toolbar',
            smartDisplay: false,
            showRefresh: true,
            height: $(window).height(),
            method: 'post',
            pageList: "[10, 15, 20]",
            search: false,
            contentType: 'application/x-www-form-urlencoded',
            dataType: 'json',
            sidePagination: 'server',
            pageNumber: 1,
            pageSize: 10,
            onlyInfoPagination: false,
            striped: true,
            columns: columns,
            onPostHeader: function () {
                $('#tableId').bootstrapTable('resetView');
            },
            queryParams: function (params) {
                return {
                    offset: (params.offset / params.limit) + 1,
                    limit: params.limit
                };
            },
            responseHandler: function (res) {
                if (res.code !== 2000) {
                    toastr.error(res.message);
                    return {
                        total: 0,
                        rows: []
                    }
                }
                return {
                    total: res.data.total,
                    rows: res.data.rows
                }
            }
        };

        $('#table').bootstrapTable(bootstrapTable);

        $('#search').click(function () {
            bootstrapTable.queryParams = function (params) {
                return {
                    offset: (params.offset / params.limit) + 1,
                    limit: params.limit
                };
            };
            var table = $('#table');
            table.bootstrapTable('destroy');
            table.bootstrapTable(bootstrapTable);
        });

        $("#addPost").click(function () {
            let data = {
                planName: $('#planNameAdd').val(),
                planPrice: $("#planPriceAdd").val(),
                planPic: $("#planPicSrcAdd").val()
            };
            $.ajax({
                url: "/SbdVoip/admin/commodityCallPlan/commodityCallPlanWebAdd",
                type: "POST",
                data: data,
                dataType: "json",
                contentType: "application/x-www-form-urlencoded",
                success: function (result) {
                    if (result.code !== 2000) {
                        toastr.error(result.message);
                        return
                    }
                    const addShow = $('#addShow');
                    addShow.modal('hide');
                    const table = $('#table');
                    table.bootstrapTable('destroy');
                    table.bootstrapTable(bootstrapTable);
                    toastr.success(result.message);
                }
            });
        });

        $("#updatePost").click(function () {
            let data = {
                id: $('#idUpdate').val(),
                planName: $('#planNameUpdate').val(),
                planPrice: $("#planPriceUpdate").val(),
                planPic: $("#planPicSrcUpdate").val()
            };
            $.ajax({
                url: "/SbdVoip/admin/commodityCallPlan/commodityCallPlanWebUpdate",
                type: "POST",
                data: data,
                dataType: "json",
                contentType: "application/x-www-form-urlencoded",
                success: function (result) {
                    if (result.code !== 2000) {
                        toastr.error(result.message);
                        return
                    }
                    var updateShow = $('#updateShow');
                    updateShow.modal('hide');
                    var table = $('#table');
                    table.bootstrapTable('destroy');
                    table.bootstrapTable(bootstrapTable);
                    toastr.success(result.message);
                }
            });
        });

        /*子数据表格*/

        let operateEventsDetail = {
            "click #showUpdateIdDetail": function (e, value, row, index) {
                $('#formDetailUpdate')[0].reset() ;
                $('#updateDetailShow').modal('show');
                $('#idDetailUpdate').val(row.id);
                $('#planNameDetailUpdate').val(row.planName);
                $('#planPriceDetailUpdate').val(row.planPrice);
                $('#planPicSrcDetailUpdate').val(row.planPic);
                updateImg([ row.planPic ], fileInputOption, "planPicDetailUpdate", "planPicSrcDetailUpdate");
            },
            "click #showDeleteIdDetail": function (e, value, row, index) {
                $.ajax({
                    url: "/SbdVoip/admin/commodityCallPlanDetail/commodityCallPlanDetailWebDelete",
                    type: "POST",
                    data: {id: row.id},
                    dataType: "json",
                    contentType: "application/x-www-form-urlencoded",
                    success: function (result) {
                        if (result.code !== 2000) {
                            toastr.error(result.message);
                            return
                        }
                        const table = $('#tableDetailShow');
                        table.bootstrapTable('destroy');
                        table.bootstrapTable(bootstrapTableShow);
                        toastr.success(result.message);
                    }
                });
            }
        };

        function actionFormatterDetail(value, row, index) {
            return [
                '<button id="showUpdateIdDetail" type="button" class="btn btn-warning">修改</button>',
                '<button id="showDeleteIdDetail" type="button" class="btn btn-danger">删除</button>'
            ].join('');
        }

        let columnsShow = [
            // {checkbox: true, 'data-halign': 'center', width: 50},
            {field: 'planName', title: '礼包详情名称', align: 'center', width: 300},
            {field: 'planPrice', title: '礼包详情价值', align: 'center', width: 100},
            {field: 'planPic', title: '礼包详情图', align: 'center', width: 300, formatter: planPicFormatter},
            {field: 'createTime', title: '创建时间', align: 'center', width: 272, formatter: formatDate},
            {title: '操作', align: 'center', formatter: actionFormatterDetail, events: operateEventsDetail, width: 500}
        ];

        let bootstrapTableShow = {
            url: '/SbdVoip/admin/commodityCallPlanDetail/commodityCallPlanDetailWebList',
            pagination: true,
            toolbar: '#toolbarShow',
            smartDisplay: false,
            showRefresh : true,
            height: $('#detailShow').height() - 172,
            method: 'post',
            pageList: "[10, 15, 20]",
            search: false,
            contentType: 'application/x-www-form-urlencoded',
            dataType: 'json',
            sidePagination: 'server',
            pageNumber : 1,
            pageSize: 10,
            onlyInfoPagination: false,
            striped: true,
            columns: columnsShow,
            onPostHeader: function(){
                $('#tableDetailShow').bootstrapTable('resetView');
            },
            queryParams: function (params) {
                return {
                    offset: (params.offset / params.limit) + 1,
                    limit: params.limit,
                    callPlan: sid
                };
            },
            responseHandler: function (res) {
                if (res.code !== 2000) {
                    toastr.error(res.message);
                    return {
                        total: 0,
                        rows: []
                    }
                }
                return {
                    total: res.data.total,
                    rows: res.data.rows
                }
            }
        };

        $('#searchShow').click(function () {
            bootstrapTableShow.queryParams = function (params) {
                return {
                    offset: (params.offset / params.limit) + 1,
                    limit: params.limit,
                    callPlan: sid
                };
            };
            let tableDetailShow = $('#tableDetailShow');
            tableDetailShow.bootstrapTable('destroy');
            tableDetailShow.bootstrapTable(bootstrapTableShow);
        });

        addImg([], fileInputOption, "planPicDetailAdd", "planPicSrcDetailAdd");
        $("#addDetailModal").click(function () {
            $('#formDetailAdd')[0].reset() ;
            $('#addDetailShow').modal('show');
        });

        $("#addDetailPost").click(function () {
            let data = {
                planName: $('#planNameDetailAdd').val(),
                planPrice: $("#planPriceDetailAdd").val(),
                planPic: $("#planPicSrcDetailAdd").val(),
                callPlan: sid
            };
            $.ajax({
                url: "/SbdVoip/admin/commodityCallPlanDetail/commodityCallPlanDetailWebAdd",
                type: "POST",
                data: data,
                dataType: "json",
                contentType: "application/x-www-form-urlencoded",
                success: function (result) {
                    if (result.code !== 2000) {
                        toastr.error(result.message);
                        return
                    }
                    const addShow = $('#addDetailShow');
                    addShow.modal('hide');
                    const table = $('#tableDetailShow');
                    table.bootstrapTable('destroy');
                    table.bootstrapTable(bootstrapTableShow);
                    toastr.success(result.message);
                }
            });
        });

        $("#updateDetailPost").click(function () {
            let data = {
                id: $('#idDetailUpdate').val(),
                planName: $('#planNameDetailUpdate').val(),
                planPrice: $("#planPriceDetailUpdate").val(),
                planPic: $("#planPicSrcDetailUpdate").val()
            };
            $.ajax({
                url: "/SbdVoip/admin/commodityCallPlanDetail/commodityCallPlanDetailWebUpdate",
                type: "POST",
                data: data,
                dataType: "json",
                contentType: "application/x-www-form-urlencoded",
                success: function (result) {
                    if (result.code !== 2000) {
                        toastr.error(result.message);
                        return
                    }
                    var updateShow = $('#updateDetailShow');
                    updateShow.modal('hide');
                    var table = $('#tableDetailShow');
                    table.bootstrapTable('destroy');
                    table.bootstrapTable(bootstrapTableShow);
                    toastr.success(result.message);
                }
            });
        });

        $("#updateDetailShow").on("hidden.bs.modal", function () {
            $("body").attr("class", "modal-open");
        });
        $("#addDetailShow").on("hidden.bs.modal", function () {
            $("body").attr("class", "modal-open");
        });
    });
</script>
